package SparkExercises.ZuoYe4;


import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang.RandomStringUtils;
import scala.util.parsing.json.JSONObject;

import java.io.*;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

/**
 * 产生5位长度的随机字符串，中文环境下是乱码
 * RandomStringUtils.random(5);
 *
 * //使用指定的字符生成5位长度的随机字符串
 * RandomStringUtils.random(5, new char[]{'a','b','c','d','e','f', '1', '2', '3'});
 *
 * //生成指定长度的字母和数字的随机组合字符串
 * RandomStringUtils.randomAlphanumeric(5);
 *
 * //生成随机数字字符串
 * RandomStringUtils.randomNumeric(5);
 *
 * //生成随机[a-z]字符串，包含大小写
 * RandomStringUtils.randomAlphabetic(5);
 *
 * //生成从ASCII 32到126组成的随机字符串
 * RandomStringUtils.randomAscii(4);
 */
public class RandomData {

    public static void main(String[] args) throws IOException {
        Random random = new Random();

        List<String> strings = Arrays.asList("信息学院", "机械学院", "人文学院");

        List<String> strings1 = Arrays.asList(RandomStringUtils.randomAlphabetic(5),RandomStringUtils.randomAlphabetic(5), RandomStringUtils.randomAlphabetic(5));


        List<String> strings2 = Arrays.asList("男", "女");

        List<String> strings3 = Arrays.asList("13", "18", "17");

        List<String> strings4 = Arrays.asList("6", "7", "8", "9");

        List<String> strings5 = Arrays.asList("1","2","3");


        File file = new File("./data/demoData1.json");

        Writer write = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");




        for (int i = 0; i < 1001; i++) {
            int s = random.nextInt(3);

            // 姓名
            String name = strings1.get(s);
            // 年龄
            String age = strings5.get(s);
            String age1 = age + RandomStringUtils.randomNumeric(1);
            // 性别
            int s2 = random.nextInt(2);
            String sex = strings2.get(s2);
            // 学院
            String institute = strings.get(s);
            // 成绩
            int s3 = random.nextInt(4);
            String score = strings4.get(s3);
            String score1 = score + RandomStringUtils.randomNumeric(1);
            // 电话
            String s1 = strings3.get(s);
            String phone = s1 + RandomStringUtils.randomNumeric(9);
            // 学号
            String studentId = "20200" + RandomStringUtils.randomNumeric(6);

            String json = "{\"studentId\":"+"\""+studentId+"\""+","+"\"name\":"+"\""+ name+ "\""+"," + "\"age\":" + age1 + "," + "\"sex\":" + "\""+sex + "\"" + "," + "\"institute\":"+"\"" + institute +"\""+"," +"\"score\":" + score1 +","+"\"phone\":" + phone +"}";
            System.out.println(json);
            write.write(json);
            write.write("\n");


        }
        write.flush();
        write.close();






    }


}
